<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>react初始配置 - (power up)</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="Kevin Jiang" /><meta name="description" content="下面webpack babel react 2018年最新最小化配置模板 package.js 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 { &amp;#34;name&amp;#34;: &amp;#34;{{NAME}}&amp;#34;, &amp;#34;version&amp;#34;: &amp;#34;1.0.0&amp;#34;, &amp;#34;description&amp;#34;: &amp;#34;{{DESCRIPTION}}&amp;#34;, &amp;#34;main&amp;#34;: &amp;#34;index.js&amp;#34;, &amp;#34;scripts&amp;#34;: { &amp;#34;start&amp;#34;: &amp;#34;webpack-dev-server&amp;#34;," /><meta name="keywords" content="KevinJiang, AI大模型, AI落地, 全栈工程师, Java, Spring Boot" />






<meta name="generator" content="Hugo 0.84.4 with theme even" />


<link rel="canonical" href="http://kevinjiang.info/post/react%E5%88%9D%E5%A7%8B%E9%85%8D%E7%BD%AE/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.78f8f17bab244b9ee62ad16480c9584d5fc2db06ae20681d1ca225cefd80767c.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="react初始配置" />
<meta property="og:description" content="下面webpack babel react 2018年最新最小化配置模板 package.js 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 { &#34;name&#34;: &#34;{{NAME}}&#34;, &#34;version&#34;: &#34;1.0.0&#34;, &#34;description&#34;: &#34;{{DESCRIPTION}}&#34;, &#34;main&#34;: &#34;index.js&#34;, &#34;scripts&#34;: { &#34;start&#34;: &#34;webpack-dev-server&#34;," />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://kevinjiang.info/post/react%E5%88%9D%E5%A7%8B%E9%85%8D%E7%BD%AE/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2018-02-13T17:11:29+00:00" />
<meta property="article:modified_time" content="2018-02-13T17:11:29+00:00" />

<meta itemprop="name" content="react初始配置">
<meta itemprop="description" content="下面webpack babel react 2018年最新最小化配置模板 package.js 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 { &#34;name&#34;: &#34;{{NAME}}&#34;, &#34;version&#34;: &#34;1.0.0&#34;, &#34;description&#34;: &#34;{{DESCRIPTION}}&#34;, &#34;main&#34;: &#34;index.js&#34;, &#34;scripts&#34;: { &#34;start&#34;: &#34;webpack-dev-server&#34;,"><meta itemprop="datePublished" content="2018-02-13T17:11:29+00:00" />
<meta itemprop="dateModified" content="2018-02-13T17:11:29+00:00" />
<meta itemprop="wordCount" content="341">
<meta itemprop="keywords" content="react,webpack," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="react初始配置"/>
<meta name="twitter:description" content="下面webpack babel react 2018年最新最小化配置模板 package.js 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 { &#34;name&#34;: &#34;{{NAME}}&#34;, &#34;version&#34;: &#34;1.0.0&#34;, &#34;description&#34;: &#34;{{DESCRIPTION}}&#34;, &#34;main&#34;: &#34;index.js&#34;, &#34;scripts&#34;: { &#34;start&#34;: &#34;webpack-dev-server&#34;,"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">(Power up)</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">首页</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a><a href="/resume/">
        <li class="mobile-menu-item">简历</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">(Power up)</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">首页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/resume/">简历</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">react初始配置</h1>

      <div class="post-meta">
        <span class="post-time"> 2018-02-13 </span>
        
          <span class="more-meta"> 约 341 字 </span>
          <span class="more-meta"> 预计阅读 1 分钟 </span>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents"></nav>
  </div>
</div>
    <div class="post-content">
      <p>下面webpack babel react 2018年最新最小化配置模板</p>
<!-- raw HTML omitted -->
<p>package.js</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">{
    &#34;name&#34;: &#34;{{NAME}}&#34;,
    &#34;version&#34;: &#34;1.0.0&#34;,
    &#34;description&#34;: &#34;{{DESCRIPTION}}&#34;,
    &#34;main&#34;: &#34;index.js&#34;,
    &#34;scripts&#34;: {
        &#34;start&#34;: &#34;webpack-dev-server&#34;,
        &#34;test&#34;: &#34;echo \&#34;Error: no test specified\&#34; &amp;&amp; exit 1&#34;
    },
    &#34;repository&#34;: {
        &#34;type&#34;: &#34;git&#34;,
        &#34;url&#34;: &#34;&#34;
    },
    &#34;author&#34;: &#34;&#34;,
    &#34;license&#34;: &#34;LexisNexis&#34;,
    &#34;devDependencies&#34;: {
        &#34;babel-core&#34;: &#34;^6.26.0&#34;,
        &#34;babel-loader&#34;: &#34;^7.1.2&#34;,
        &#34;babel-preset-env&#34;: &#34;^1.6.1&#34;,
        &#34;babel-preset-react&#34;: &#34;^6.24.1&#34;,
        &#34;html-webpack-plugin&#34;: &#34;^2.30.1&#34;,
        &#34;path&#34;: &#34;^0.12.7&#34;,
        &#34;webpack&#34;: &#34;^3.11.0&#34;,
        &#34;webpack-dev-server&#34;: &#34;^2.11.1&#34;
    },
    &#34;dependencies&#34;: {
        &#34;react&#34;: &#34;^16.2.0&#34;,
        &#34;react-dom&#34;: &#34;^16.2.0&#34;
    }
}

</code></pre></td></tr></table>
</div>
</div><p>webpack.config.js</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">const path = require(&#39;path&#39;);
const HtmlWebpackPlugin = require(&#39;html-webpack-plugin&#39;);

const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
  template: &#39;./client/index.html&#39;,
  filename: &#39;index.html&#39;,
  inject: &#39;body&#39;
});

module.exports = {
    entry: &#39;./client/index.jsx&#39;,
    output: {
        path: path.resolve(&#39;dist&#39;),
        filename: &#39;app.js&#39;
    },
    module: {
        loaders: [
            { test: /\.js$/, loader: &#39;babel-loader&#39;, exclude: /node_modules/ },
            { test: /\.jsx$/, loader: &#39;babel-loader&#39;, exclude: /node_modules/ }
        ]
    },
    plugins: [HtmlWebpackPluginConfig]
};
</code></pre></td></tr></table>
</div>
</div><p>.babelrc</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">{&#34;presets&#34;: [&#34;env&#34;, &#34;react&#34;]}
</code></pre></td></tr></table>
</div>
</div><p>client/index.html</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset=&#34;utf-8&#34;&gt;
    &lt;title&gt;React App Setup&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&#34;app&#34;&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre></td></tr></table>
</div>
</div><p>client/index.jsx</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">import React from &#39;react&#39;;
import {render} from &#39;react-dom&#39;;
import MyComponent from &#39;./MyComponent.jsx&#39;;

class App extends React.Component {
    render () {
        return (
	    &lt;div&gt;
              &lt;h1&gt;Hello React.js&lt;/h1&gt;
	      &lt;MyComponent/&gt;
	    &lt;/div&gt;
        );
    }
}

render(&lt;App/&gt;, document.getElementById(&#39;app&#39;));
</code></pre></td></tr></table>
</div>
</div><p>client/MyComponent.jsx</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">import React from &#39;react&#39;;

export default class MyComponent extends React.Component {
    render () {
        return (
            &lt;div&gt;This is my component&lt;/div&gt;
        );
    }
}
</code></pre></td></tr></table>
</div>
</div><p>然后执行<code>npm install</code>安装必要的依赖</p>
<p>最后执行<code>npm start</code></p>

    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">Kevin Jiang</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2018-02-13
        
    </span>
  </p>
  
  <p class="copyright-item">
    <span class="item-title">许可协议</span>
    <span class="item-content"><a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a></span>
  </p>
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/wechat_pay_1242x1242.jpg">
        <span>微信打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/alipay_600x600.jpg">
        <span>支付宝打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/react/">react</a>
          <a href="/tags/webpack/">webpack</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/clojure/clojure%E5%8E%8B%E7%BC%A9%E7%9B%AE%E5%BD%95%E4%B8%BAzip/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">Clojure压缩目录为zip</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/searchengine/solr7%E9%85%8D%E7%BD%AE%E5%90%8C%E4%B9%89%E8%AF%8D/">
            <span class="next-text nav-default">solr7配置同义词</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:wenlin1988@126.com" class="iconfont icon-email" title="email"></a>
      <a href="https://www.linkedin.com/in/%E6%96%87%E6%9E%97-%E8%92%8B-0a3204126/" class="iconfont icon-linkedin" title="linkedin"></a>
      <a href="https://github.com/kevindragon" class="iconfont icon-github" title="github"></a>
  <a href="http://kevinjiang.info/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 -
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  

  <span class="copyright-year">
    &copy;
    2015 -
    2023<span class="heart"><i class="iconfont icon-heart"></i></span><span>Kevin Jiang</span>
    <a href="https://beian.miit.gov.cn/" target="_blank">湘ICP备2022022745号</a>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.c99b103c33d1539acf3025e1913697534542c4a5aa5af0ccc20475ed2863603b.js"></script>
  <script type="text/javascript">
    window.MathJax = {
      tex: {
        inlineMath: [['$','$'], ['\\(','\\)']],
        tags: 'ams',
        }
    };
  </script>
  <script type="text/javascript" async src="/lib/mathjax/es5/tex-mml-chtml.js"></script>

<script id="baidu_analytics">
  var _hmt = _hmt || [];
  (function() {
    if (window.location.hostname === 'localhost') return;
    var hm = document.createElement("script"); hm.async = true;
    hm.src = "https://hm.baidu.com/hm.js?b73ff6d4afc4af9e582d8a5dc068bab9";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>






</body>
</html>
